// 导入：类型、接口、模块、组件、样式
import { Component } from "react";

// 类组件
class Index extends Component {
  state = {
    num: 0,
  };
  render() {
    return (
      <>
        <h1>num {this.state.num}</h1>
      </>
    );
  }

  componentDidMount() {
    this.setState({ num: this.state.num + 1 });
    console.log("1", this.state.num);
    this.setState({ num: this.state.num + 1 });
    console.log("2", this.state.num);
    setTimeout(() => {
      this.setState({ num: this.state.num + 1 });
      console.log("3", this.state.num);
    }, 0);
    setTimeout(() => {
      this.setState({ num: this.state.num + 1 });
      console.log("4", this.state.num);
    }, 0);
  }

  // componentDidMount() {
  // this.setState({ num: this.state.num + 1 });
  // this.setState({ num: this.state.num + 1 });
  // document.onclick = () => {
  //   this.setState({ num: this.state.num + 1 });
  //   this.setState({ num: this.state.num + 1 });
  // };
  // setTimeout(() => {
  //   this.setState({ num: this.state.num + 1 });
  //   this.setState({ num: this.state.num + 1 });
  // });
  // }
}

export default Index;
